package cn.yunyichina.provider.report.service;

import javax.validation.ConstraintViolation;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Created by Lullaby on 2017/12/15
 */
public class BaseService {

    protected <T> List<String> getConstraintMessageList(Set<ConstraintViolation<T>> constraintViolationSet) {
        if (constraintViolationSet.isEmpty()) {
            return null;
        }

        List<String> result = new ArrayList<>();
        for (ConstraintViolation violation : constraintViolationSet) {
            result.add(violation.getPropertyPath() + " " + violation.getMessage());
        }

        return result;
    }

}
